/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.app.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Thuan
 */
@Entity
@Table(name = "AccountOfStudent")
@NamedQueries({
    @NamedQuery(name = "AccountOfStudent.findAll", query = "SELECT a FROM AccountOfStudent a"),
    @NamedQuery(name = "AccountOfStudent.findByStudentId", query = "SELECT a FROM AccountOfStudent a WHERE a.accountOfStudentPK.studentId = :studentId"),
    @NamedQuery(name = "AccountOfStudent.findBySemesterId", query = "SELECT a FROM AccountOfStudent a WHERE a.accountOfStudentPK.semesterId = :semesterId"),
    @NamedQuery(name = "AccountOfStudent.findByUsername", query = "SELECT a FROM AccountOfStudent a WHERE a.username = :username"),
    @NamedQuery(name = "AccountOfStudent.findByPassword", query = "SELECT a FROM AccountOfStudent a WHERE a.password = :password")})
public class AccountOfStudent implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AccountOfStudentPK accountOfStudentPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "username")
    private String username;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "password")
    private String password;
    @JoinColumn(name = "studentId", referencedColumnName = "studentId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Student student;
    @JoinColumn(name = "semesterId", referencedColumnName = "semesterId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Semester semester;

    public AccountOfStudent() {
    }

    public AccountOfStudent(AccountOfStudentPK accountOfStudentPK) {
        this.accountOfStudentPK = accountOfStudentPK;
    }

    public AccountOfStudent(AccountOfStudentPK accountOfStudentPK, String username, String password) {
        this.accountOfStudentPK = accountOfStudentPK;
        this.username = username;
        this.password = password;
    }

    public AccountOfStudent(int studentId, int semesterId) {
        this.accountOfStudentPK = new AccountOfStudentPK(studentId, semesterId);
    }

    public AccountOfStudentPK getAccountOfStudentPK() {
        return accountOfStudentPK;
    }

    public void setAccountOfStudentPK(AccountOfStudentPK accountOfStudentPK) {
        this.accountOfStudentPK = accountOfStudentPK;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Semester getSemester() {
        return semester;
    }

    public void setSemester(Semester semester) {
        this.semester = semester;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accountOfStudentPK != null ? accountOfStudentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AccountOfStudent)) {
            return false;
        }
        AccountOfStudent other = (AccountOfStudent) object;
        if ((this.accountOfStudentPK == null && other.accountOfStudentPK != null) || (this.accountOfStudentPK != null && !this.accountOfStudentPK.equals(other.accountOfStudentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.app.model.AccountOfStudent[ accountOfStudentPK=" + accountOfStudentPK + " ]";
    }

}
